package leetcode.l0607;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Retain
 * @date 2021/6/7 14:56
 */
public class Medium_全排列_46 {
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        backTrack(nums,new LinkedList<>());
        return res;
    }

    public void backTrack(int[] nums,LinkedList<Integer> track) {
        if (track.size() == nums.length) {
            res.add(new LinkedList<>(track));
            return;
        }

        for (int num : nums) {
            if (track.contains(num)) {
                continue;
            }
            track.add(num);
            backTrack(nums,track);
            track.removeLast();
        }
    }
}
